home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01b.txt
/
000133_icon-group-sender_Tue Aug 7 08:51:56 2001.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f77FkWQ23106
for icon-group-addresses; Tue, 7 Aug 2001 08:46:32 -0700 (MST)
Message-Id: <200108071546.f77FkWQ23106@baskerville.CS.Arizona.EDU>
Date: Tue, 07 Aug 2001 13:07:16 +0200
From: Anders Holtsberg <anders.holtsberg@decuma.com>
X-Accept-Language: en
To: icon-group@cs.arizona.edu
Subject: Sorting
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 1011
What is the simplest way to sort a list of records according to
one of the fields? It seems hat this is not a one liner, or is
it? My quick hack is this:
procedure sortbyfield(thelist, i)
t := table(&null)
every e := !thelist do t[e[i]] := e;
s := sort(t, 1)
w := []
every put(w, (!s)[2])
return w
end
For tables one can give a second argument to the sort procedure,
but for lists the second argument is simply ignored.
One simple for future enhancement to Icon is to use the above
semantics for a two argument call to sort, where the first
argument is either a list of records or a list of lists. Even
better is to also accept a string as second argument for the
case that the first argument is a list of records. Is this
sensible?
Anders Holtsberg
--
_______________________________________________________________
Anders Holtsberg Decuma AB
tel +46 709 596305 Ideon V�xthuset
anders.holtsberg@decuma.se S-223 70 Lund, Sweden